home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_100 / 104_01 / submit.c < prev    next >
Text File  |  1980-01-01  |  7KB  |  279 lines

  1. /********************************************************/
  2. /*                            */
  3. /*    copyright(c) 1981 By Mike Bernson        */
  4. /*                            */
  5. /*    submit command for cpm 2.x            */
  6. /*    read input file and convert to $$$.sub with    */
  7. /*    $1-$9 to pram from comand line and convert    */
  8. /*    ^a to control character                */
  9. /*                            */
  10. /********************************************************/
  11.  
  12. #define ERROR    -1        /* error return value */
  13. #define LF    0x0a        /* value used for line feed */
  14. #define CR    0x0d        /* value used for return */
  15. #define ENDFILE    0x1a        /* value used for end of file */
  16.  
  17. char infcb[36];            /* pointer to input fcb */
  18. char outfcb[36];        /* output fcb */
  19.  
  20. char *prt;            /* just a spare pointer */
  21. int  inpoff;            /* input buffer offset */
  22. int  outoff;            /* output buffer offset */
  23.  
  24. int  line;            /* current line number */
  25.  
  26. char inbuff[128];        /* input buffer */
  27. char outbuff[17000];        /* output buffer */
  28.  
  29. /********************************************************/
  30. /*                            */
  31. /*    main                        */
  32. /*                            */
  33. /*    function:    open input and output data file */
  34. /*            also process data and output    */
  35. /*            data to $$$.sub and set loc 8 ff*/
  36. /*                            */
  37. /*    Date written:    Jan 28, 1981 by Mike Bernson    */
  38. /*                            */
  39. /********************************************************/
  40. main(argc,argv)
  41. int argc;        /* number of arg on command line +1 */
  42. int argv[];        /* pointer to each arg on command line */
  43. {
  44.     char filename[132];    /* hold input file name */
  45.     
  46.     strcpy(filename,argv[1]);
  47.     strcat(filename,".sub");
  48.  
  49.     if (open(infcb,filename) == ERROR) {
  50.         infcb[0]=1;        /* try drive a */
  51.         if (bdos(15,infcb) == 0xff) {
  52.             puts("Input file not found");
  53.             exit();
  54.             }
  55.         }
  56.     for(line=argc; line<12; argv[line++]="");
  57.     inpoff=128;
  58.     line=1;
  59.  
  60.     /* process input file and write output */
  61.     while(1) {
  62.         doinput(argv+1);
  63.         dooutput();
  64.         }
  65.     }
  66.  
  67.  
  68. /********************************************************/
  69. /*                            */
  70. /*    doinput                        */
  71. /*                            */
  72. /*    function:    to proccess input buffer and    */
  73. /*            change $1-$9 to text needed and    */
  74. /*            convert '^'a to control char    */
  75. /*                            */
  76. /*    date written    Jan 28, 1981 By Mike Bernson    */
  77. /*                            */
  78. /********************************************************/
  79. doinput(parm)
  80. int parm[];
  81. {
  82.     int current;   /* current character working on */
  83.  
  84.     outoff=1;    /* set output offset to zero */
  85.  
  86.     /* pick up 1 line of input */
  87.     while(outoff<120) {
  88.  
  89.         /* get charcter and see what need to be done */
  90.         switch(current=getbuff()) {
  91.  
  92.         /* end of file  */
  93.         case ENDFILE :
  94.             done();
  95.     
  96.         /* '$' can be $1-$9 or $$ */
  97.         case '$' :
  98.             if ((current=getbuff())=='$') {
  99.                 putbuff('$');
  100.                 break;
  101.                 }
  102.             if (current>='0' && current<='9') {
  103.                 prt=parm[current-'0'];
  104.                 while(*prt) putbuff(*prt++);
  105.                 break;
  106.                 }
  107.             error("Invalid parmeter");
  108.             break;
  109.  
  110.         /* check for control chraracter */
  111.         case '^' :
  112.             current=getbuff();
  113.             if (current>='A' && current<='Z')
  114.                 putbuff(current-'@');
  115.                 else error("Invalid control character ");
  116.             break;
  117.         
  118.         /* check for end of line */
  119.         case CR :
  120.             return;
  121.     
  122.         /* line    feed ingore */
  123.         case LF :
  124.             break;
  125.         
  126.         /* must be a viald cjaracter put in output buffer */
  127.         default:
  128.             putbuff(current);
  129.         }}
  130.     }
  131.  
  132. /********************************************************/
  133. /*                            */
  134. /*    dooutput                    */
  135. /*                            */
  136. /*    function:    to write output record to disk    */
  137. /*            put character count at offset 0 */
  138. /*                            */
  139. /*    date written:    dec 16, 1980 By Mike Bernson    */
  140. /*                            */
  141. /********************************************************/
  142. dooutput()
  143. {
  144.     outbuff[(line-1)*128]=outoff-1; /* character count */
  145.  
  146.     /* zero buffer till end */
  147.     while(outoff<128) putbuff(0);
  148.     if (++line>148)    error("Too many    lines");
  149.     }
  150.  
  151. /********************************************************/
  152. /*                            */
  153. /*    done                        */
  154. /*                            */
  155. /*    function:    to write output buffer out    */
  156. /*            in backward record format    */
  157. /*                            */
  158. /*    Date written:    Dec 16, 1980 By Mike Bernson    */
  159. /*                            */
  160. /********************************************************/
  161. done()
  162. {
  163.     char temp;
  164.  
  165.     /* create output file on disk a    */
  166.     if (open(outfcb,"A:$$$.SUB") != ERROR) 
  167.         outfcb[32]=outfcb[15];
  168.     else if (create(outfcb,"A:$$$.SUB") == ERROR) {
  169.         puts("Output File not created");
  170.         exit();
  171.         }
  172.     while(--line) {
  173.         if (write(outfcb,outbuff+128*(line-1),1) == ERROR) {
  174.             error("Disk is Full");
  175.             exit();
  176.             }
  177.         }
  178.     close(outfcb);
  179.     prt=8;
  180.     *prt=255;
  181.     exit();
  182.     }
  183.  
  184.  
  185. /********************************************************/
  186. /*                            */
  187. /*    getbuff                        */
  188. /*                            */
  189. /*    function:    to getn next character from     */
  190. /*            from input buffer and convert    */
  191. /*            to upper case            */
  192. /*                            */
  193. /*    date written:    Dec 16, 1980 by Mike Bernson    */
  194. /*                            */
  195. /********************************************************/
  196. getbuff()
  197. {
  198.     if (inpoff == 128) {
  199.         if (read(infcb,inbuff,1) == ERROR) return ENDFILE;
  200.         inpoff=0;
  201.         }
  202.     return toupper(inbuff[inpoff++]);
  203.     }
  204.  
  205. /********************************************************/
  206. /*                            */
  207. /*    putbuff                        */
  208. /*                            */
  209. /*    function:    to write chracter to output     */
  210. /*            buff and inc offset        */
  211. /*                            */
  212. /*    input:        character to write        */
  213. /*                            */
  214. /*    date written:    Dec 16, 1980 By Mike Bernson    */
  215. /*                            */
  216. /********************************************************/
  217. putbuff(data)
  218. char data;
  219. {
  220.     outbuff[(line-1)*128+outoff++]=data;
  221.     }
  222.  
  223.  
  224. /********************************************************/
  225. /*                            */
  226. /*    error                        */
  227. /*                            */
  228. /*    function:    to print error message follow    */
  229. /*            by at line (line number)    */
  230. /*                            */
  231. /*    date written:    dec 16, 1980 By Mike Bernson    */
  232. /*                            */
  233. /********************************************************/
  234. error(msg)
  235. char *msg;
  236. {
  237.     puts(msg);        /* print error message */
  238.     puts(" at line ");    /* print "at line" */
  239.     outdec(line);        /* print line number */
  240.     exit() ;        /* end back to cpm */
  241.     }
  242.  
  243. /********************************************************/
  244. /*                            */
  245. /*    outdec                        */
  246. /*                            */
  247. /*    function:    to output number in dec from    */
  248. /*            to console            */
  249. /*                            */
  250. /*    date written:    Dec 16, 1980 By Mike Bernson    */
  251. /*                            */
  252. /********************************************************/
  253. outdec(number)
  254. int number;
  255. {
  256.     char zero,num;
  257.     int  place;
  258.  
  259.     place=10000;
  260.     zero=0;
  261.  
  262.     while(place>0) {
  263.         num=number/place+'0'; /* get current digit */
  264.         if (num != '0' || place ==1 || zero) {
  265.             zero=1; /* set zero suppress */
  266.             putch(num); /* print character */
  267.             }
  268.         number=number % place;
  269.         place=place/10;
  270.         }
  271.     }
  272. place=place/10;
  273.         }
  274.     }
  275. 10;
  276.         }
  277.     }
  278. ;
  279.         place=place/10;